package com.cfc.personalproject;

import com.cfc.personalproject.db.model.biz.PlaceBase;
import com.cfc.personalproject.model.C_ResultModel;
import com.cfc.personalproject.model.C_ResultModel_Page;
import com.cfc.personalproject.service.PlaceBaseService;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: anxiaojian
 * @Date: 2020/10/26 17:09
 * @Description:
 */
@Controller
public class TestController {

    private static final Logger logger = LoggerFactory.getLogger(TestController.class);

    @Autowired
    private PlaceBaseService placeBaseService;

    @ResponseBody
    @RequestMapping(value = "/test",method = RequestMethod.GET)
    public String test(){
        return "test";
    }

    @ResponseBody
    @RequestMapping(value = "/testData",method = RequestMethod.GET)
    public ResponseEntity<C_ResultModel> testData(){
        C_ResultModel result = new C_ResultModel();
        result.setCode("000000");
        result.setMessage("推送消息发送成功");
        System.out.println("===================");
        return new ResponseEntity<C_ResultModel>(result, HttpStatus.OK);
    }

    /**
     * 获取信息列表接口
     * @return
     */
    @RequestMapping(value = "getPlaceListInfo",method = RequestMethod.GET)
    public String getPlaceListInfo(Model model,@RequestParam(value = "pageIndex",defaultValue = "1") Integer pageIndex,
                                   @RequestParam(value = "pageSize",defaultValue = "20") Integer pageSize){
        PageInfo<PlaceBase> pageInfo = placeBaseService.findList(pageIndex,pageSize);

        List<PlaceBase> placeBaseList = pageInfo.getList();
        int pages = pageInfo.getPages();
        logger.info("result list{},{}",placeBaseList,pages);

        C_ResultModel_Page c_resultModel_page = new C_ResultModel_Page();
        c_resultModel_page.setPages(pages);
        c_resultModel_page.setData(placeBaseList);
        c_resultModel_page.setPageNum(pageIndex);
        c_resultModel_page.setPageSize(pageSize);
        c_resultModel_page.setTotal(pageInfo.getTotal());

        model.addAttribute("model",c_resultModel_page);
        //request.setAttribute("placeList",placeBaseList);
        return "show";
    }


}
